/**
 * 
 */
package com.etrans.web.gps.common.intercepter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.etrans.web.gps.business.system.domain.SysUser;
import com.etrans.web.gps.common.Constant;

/**
 * <p>Title: LoginHandlerIntercepter.java<／p>
 * <p>Description: <／p>
 * <p>Copyright: Copyright (c) 2007<／p>
 * <p>Company: E-trans<／p>
 * 
 * @author R.Lao
 * @date 2017年6月15日
 * @time 上午8:42:49
 * @version 1.0
 */
public class LoginHandlerIntercepter  implements HandlerInterceptor {  
	      
		    @Override  
		    public void afterCompletion(HttpServletRequest request,  
		            HttpServletResponse response, Object arg2, Exception arg3)  
		            throws Exception {  
		    	System.out.println("afterCompletion");
		    }  
		  
		    @Override  
		    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,  
		            Object arg2, ModelAndView arg3) throws Exception {  
		    	System.out.println("postHandle");
		    }  
		    
		    @Override  
		    public boolean preHandle(HttpServletRequest request, 
		    		HttpServletResponse arg1,Object arg2) throws Exception { 
		    		String requestURI = request.getRequestURI();  
		    		if(requestURI.indexOf("login.html")>0){
		    			return true;
		    		}else{
		    			HttpSession session = request.getSession();  
		    			SysUser user = (SysUser) session.getAttribute(Constant.LOGIN_SESSION_NAME);  
	                	if(user!=null){  
	                		return true;  
	                	}else{  
	                		request.getRequestDispatcher("/login.jsp").forward(request,arg1);  
	                		return false;  
	                	}  
		    		}
		    }  
}
